import Vue from 'vue'
import moment from 'moment'
import 'moment/locale/zh-cn'
moment.locale('zh-cn')

Vue.filter('NumberFormat', function (value) {
  if (!value) {
    return '0'
  }
  const intPartFormat = value.toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,') // 将整数部分逢三一断
  return intPartFormat
})

Vue.filter('dayc',function(str){
  str = str.substring(0, 19);
	str = str.replace(/-/g, '/');
	return new Date(str).getTime();
})
Vue.filter('dayjs', function (value) {
  let date = new Date(value*1000);
    let y = date.getFullYear();
    let MM = date.getMonth() + 1;
    MM = MM < 10 ? ('0' + MM) : MM;
    let d = date.getDate();
    d = d < 10 ? ('0' + d) : d;
    let h = date.getHours();
    h = h < 10 ? ('0' + h) : h;
    let m = date.getMinutes();
    m = m < 10 ? ('0' + m) : m;
    let s = date.getSeconds();
    s = s < 10 ? ('0' + s) : s;
    return y + '-' + MM + '-' + d 
    // return y + '-' + MM + '-' + d + ' ' + h + ':' + m + ':' + s;
})
Vue.filter('times', function(value) {
  let date = new Date(value*1000);
  let y = date.getFullYear();
  let MM = date.getMonth() + 1;
  MM = MM < 10 ? ('0' + MM) : MM;
  let d = date.getDate();
  d = d < 10 ? ('0' + d) : d;
  let h = date.getHours();
  h = h < 10 ? ('0' + h) : h;
  let m = date.getMinutes();
  m = m < 10 ? ('0' + m) : m;
  let s = date.getSeconds();
  s = s < 10 ? ('0' + s) : s;
  return h + ':' + m ;
  // return y + '-' + MM + '-' + d + ' ' + h + ':' + m + ':' + s;
})
Vue.filter('formatDate', function(value) {
    let date = new Date(value*1000);
    let y = date.getFullYear();
    let MM = date.getMonth() + 1;
    MM = MM < 10 ? ('0' + MM) : MM;
    let d = date.getDate();
    d = d < 10 ? ('0' + d) : d;
    let h = date.getHours();
    h = h < 10 ? ('0' + h) : h;
    let m = date.getMinutes();
    m = m < 10 ? ('0' + m) : m;
    let s = date.getSeconds();
    s = s < 10 ? ('0' + s) : s;
    return y + '-' + MM + '-' + d + ' ' + h + ':' + m ;
    // return y + '-' + MM + '-' + d + ' ' + h + ':' + m + ':' + s;
})
// 时间戳转星期
Vue.filter('weeks', function week(value) {
  if (!value) return '';
  var date = new Date(value.toString().length == 10 ? value * 1000 : value);
  var week;
  if (date.getDay() == 0) week = "星期日"
  if (date.getDay() == 1) week = "星期一"
  if (date.getDay() == 2) week = "星期二"
  if (date.getDay() == 3) week = "星期三"
  if (date.getDay() == 4) week = "星期四"
  if (date.getDay() == 5) week = "星期五"
  if (date.getDay() == 6) week = "星期六"
  return week;
 })
 
Vue.filter('moment', function (dataStr, pattern = 'YYYY-MM-DD HH:mm:ss') {
  return moment(dataStr).format(pattern)
})
